#ifndef SCHEDULER_H_

#define SCHEDULER_H_

#include "object.h"
#include "eventhandler.h"
#include "timer.h"

class CmdEvent;
class DisplayTimer;

class Scheduler : public Object, public EventHandler{
	public:
		~Scheduler();

		bool scheduleAll();
		

		static bool create();
		static void destroy();
		static Scheduler& instance() {return *instance_;}

		
		//implementation of EventHandler
		virtual void onEvent( Event *event );
		virtual void onTimer( Timer *timer );

		void displayProgress();
	protected:
		Scheduler();

		void executeCmd( CmdEvent *cmd_event );

		bool scheduleNodes();
		bool scheduleNodesSequential();
		bool scheduleNodesRandom();
		bool scheduleNodesFromTrace(const char *filename);

		void scheduleSearchEvent();
		void scheduleSearchSequential();
		void scheduleSearchMerge();

		static Scheduler *instance_;

		DisplayTimer *disp_timer_;
		sim_time_t disaplay_intv_;
};

class DisplayTimer : public TimerHandler{
	public:
		DisplayTimer( Scheduler *s ) : s_(s) {}
		virtual void onTimer( Timer *timer ){
			s_->displayProgress();
		}
	protected:
		Scheduler *s_;
};

#endif /* SCHEDULER_H_ */

